package cn.cqie.attendance.manager.service.impl;

import cn.cqie.attendance.common.util.Page;
import cn.cqie.attendance.common.util.PageBean;
import cn.cqie.attendance.manager.dao.AdminLeavesDao;
import cn.cqie.attendance.manager.pojo.*;
import cn.cqie.attendance.manager.service.AdminLeavesService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author king james
 * @create 2021-07-07-{TIME}
 */
@Service
public class AdminLeavesServiceImpI implements AdminLeavesService {
    @Autowired
    private AdminLeavesDao adminLeavesDao;
    /**
     * 组合模糊查询请假信息
     * @param adminLeavesSearch 组合查询条件
     * @param pageSize 每一页的数量
     * @param pageNum 当前页的数量
     * @return
     */
    @Override
    public PageBean<AdminStudentLeave> queryAllLeavesInfo(AdminLeavesSearch adminLeavesSearch, Integer pageSize, Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);

        List<AdminStudentLeave> list  = adminLeavesDao.queryAllLeavesInfo(adminLeavesSearch);
        int total = list.size();

        if (null == list || total == 0) {
            return new PageBean<>(201,"error",list);
        }
        return new PageBean<>(200,"success",list);
    }


    /**
     * 根据学生请假id获取学生请假详情
     * @param leaveId 请假id
     * @return
     */
    @Override
    public Page<AdminStudentLeave> queryLeavesInfoById(Integer leaveId) {
        List<AdminStudentLeave> list = adminLeavesDao.queryLeavesInfoById(leaveId);
        int total = list.size();
        if (null == list ||  total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }

    /**
     * 根据学生id查询学生请假附件
     * @param stuId 学生id
     * @return
     */
    @Override
    public Page<AdminAttachment> queryAttachmentInfoById(Integer stuId) {
        List<AdminAttachment> list  = adminLeavesDao.queryAttachmentInfoById(stuId);
        int total = list.size();
        if (null == list ||  total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }

    /**
     * 根据学id查询学生请假流程管理
     * @param stuId 学生id
     * @return
     */
    @Override
    public Page<AdminLeavesDistance> queryLeaveDistanceById(Integer stuId) {
       List<AdminLeavesDistance> list = adminLeavesDao.queryLeaveDistanceById(stuId);
        int total = list.size();
        if (null == list ||  total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }
}

